package com.example.hotel_lxy.ui.activity;

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.example.hotel_lxy.R;
import com.example.hotel_lxy.application.ARouterPath;
import com.example.hotel_lxy.base.TypePay;
import com.example.hotel_lxy.bean.AddViewInfoBean;
import com.example.hotel_lxy.bean.BeanBean;
import com.example.hotel_lxy.bean.EventBean;
import com.example.hotel_lxy.bean.EventBusBean;
import com.example.hotel_lxy.bean.EventBusResereBean;
import com.example.hotel_lxy.bean.ImgBean;
import com.example.hotel_lxy.bean.RvReserveBean;
import com.example.hotel_lxy.bean.RvStandardTypeBean;
import com.example.hotel_lxy.bean.ScheduledBean;
import com.example.hotel_lxy.bean.SetUpReserveBean;
import com.example.hotel_lxy.bean.SpReserveBean;
import com.example.hotel_lxy.bean.ZeroSpSourceBean;
import com.example.hotel_lxy.net.Api;
import com.example.hotel_lxy.ui.dialog.DataGuaranteeDialog;
import com.example.hotel_lxy.ui.dialog.DataReserveAddViewDialog;
import com.example.hotel_lxy.ui.dialog.DataReserveCbDialog;
import com.example.hotel_lxy.ui.dialog.DataSelectionDialog;
import com.example.hotel_lxy.ui.dialog.ImageDialog;
import com.example.hotel_lxy.ui.dialog.ImageViewpagerDialog;
import com.example.hotel_lxy.ui.dialog.SendReserveDialog;
import com.example.hotel_lxy.utils.DatePhotoUtils;
import com.example.hotel_lxy.utils.GlideEngine;
import com.example.hotel_lxy.utils.JurisdictionUtils;
import com.example.hotel_lxy.utils.SPUtils;
import com.google.gson.Gson;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.ysxsoft.common_base.base.BaseActivity;
import com.ysxsoft.common_base.base.RBaseAdapter;
import com.ysxsoft.common_base.base.RViewHolder;
import com.ysxsoft.common_base.utils.JsonUtils;
import com.ysxsoft.common_base.utils.ToastUtils;
import com.ysxsoft.common_base.view.custom.image.RoundImageView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.PostFormBuilder;
import com.zhy.http.okhttp.callback.StringCallback;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

/**
 * 修改预定
 */
@Route(path = "/main/SetUpReserveActivity")
public class SetUpReserveActivity extends BaseActivity {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.rv_standard_type)
    RecyclerView rvStandardType;
    @BindView(R.id.line_is_meet)
    LinearLayout lineIsMeet;
    @BindView(R.id.text_tx)
    TextView textTx;
    @BindView(R.id.edit_tx)
    EditText editTx; //预订人
    @BindView(R.id.text_photo)
    EditText textPhoto;//预订人手机号
    @BindView(R.id.rg_sex)
    RadioGroup rgSex;
    @BindView(R.id.rb_male)
    RadioButton rbMale;
    @BindView(R.id.rb_female)
    RadioButton rbFemale;
    @BindView(R.id.text_time1)
    TextView textTime1;
    @BindView(R.id.rb_noon)
    RadioButton rbNoon;
    @BindView(R.id.rb_night)
    RadioButton rbNight;
    @BindView(R.id.radioGroup1)
    RadioGroup radioGroup1;
    @BindView(R.id.text_time2)
    TextView textTime2;
    @BindView(R.id.rb_noon2)
    RadioButton rbNoon2;
    @BindView(R.id.rb_night2)
    RadioButton rbNight2;
    @BindView(R.id.radioGroup2)
    RadioGroup radioGroup2;
    @BindView(R.id.edit_cb)
    EditText editCb;
    @BindView(R.id.text_Cb)
    TextView textCb;


    @BindView(R.id.line_add_view)
    LinearLayout lineAddView;
    @BindView(R.id.text_Add)
    TextView textAdd;
    @BindView(R.id.rv_hetong)
    RecyclerView rvHetong;
    @BindView(R.id.rv_qita)
    RecyclerView rvQita;
    @BindView(R.id.text1)
    TextView text1;

    @BindView(R.id.text_desk)
    EditText textDesk;
    @BindView(R.id.prepare_desk)
    EditText prepareDesk;
    @BindView(R.id.img_Cb)
    ImageView imgCb;
    @BindView(R.id.tv_source)
    TextView tvSource;
    @BindView(R.id.tv_view)
    TextView tvView;
    @BindView(R.id.text_service)
    TextView textService;

    @BindView(R.id.text_reserve)
    TextView textReserve;
    @BindView(R.id.text_message)
    TextView textMessage;
    @BindView(R.id.edit_content)
    EditText editContent;

    @BindView(R.id.rv_type)
    RecyclerView rvType;
    @BindView(R.id.text2)
    TextView text2;
    @BindView(R.id.text3)
    TextView text3;
    @BindView(R.id.text_caidan)
    TextView textCaidan;
    @BindView(R.id.line6)
    LinearLayout line6;

    private View view;
    private List<RvReserveBean> RvReserveList = new ArrayList<>();
    private int type_time;
    private TextView text_title;
    private List<TypePay> SpTypeList = new ArrayList<>();
    private List<TypePay> SpModeList = new ArrayList<>();
    private List<String> mlist_hetong = new ArrayList<>();
    private List<String> mlist_qita = new ArrayList<>();

    private List<ContractsBean> mlist_rvhetong = new ArrayList<>();
    private List<OthersBean> mlist_rvqita = new ArrayList<>();

    List<String> mlist = new ArrayList<>();
    int img_type;
    List<ZeroSpSourceBean.DataBean.ListBean> list;
    TextView tv_type, tv_type_id;
    TextView tv_mode, tv_mode_id;

    private TextView dbr_id;
    private String director_id;
    private String source_id;

    //宴会厅di
    private String bid;

    //开始日期
    String begin_year = "";
    String begin_month = "";
    String begin_day = "";
    String begin_night = "1";//1中午2晚上
    //结束日期
    String end_year = "";
    String end_month = "";
    String end_day = "";
    String end_night = "1";//1中午2晚上
    //增值
    private String increase_money;//增值服务费
    private String increase = "";//增值服务id
    //性别
    private String sex = "1";//1男2女
    //类型id
    private String tid = "";
    //新郎新娘
    private String banquet_name = "";
    private List<BanquetNameBean> BanquetNamelsit = new ArrayList<>();//新郎新娘信息
    //餐标id
    private String cb_id = "";
    private String cb_did = "";
    private String d_money = "";
    //所选菜品id
    private String cid = "";
    //上传合同
    private String contract = "";
    //其他信息
    private String other = "";
    //是不是会议
    private String is_meeting = "1"; //1是2不是
    //确认方式
    private String confirm = "";
    private List<Object> mlsit = new ArrayList<>();//预收

    private EditText money;
    private EditText number;
    private ImageView imgview;
    private TextView text_img;
    RadioButton rbYs;
    RadioButton rbDb;

    LinearLayout lineDbr;
    TextView edit_dbr;
    ImageView img_dbr;
    TextView edit_dbr_id;
    LinearLayout line_ys;
    TextView ids;
    TextView bh;
    private View view1;
    //担保人iD
    List<RvStandardTypeBean.DataBean.TypeBean> types;
    private int type;
    //区分预收款第几个布局
    private int img;
    private List<AddViewImg> addViewImgList = new ArrayList<>();

    @Autowired
    String id;

    private String string;
    private boolean aBoolean = true;

    public static void start(String id) {
        ARouter.getInstance().build(ARouterPath.getSetUpReserveActivity())
                .withString("id", id)
                .navigation();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_setup_reserve;
    }

    @Override
    public void doWork() {
        super.doWork();
        ARouter.getInstance().inject(this);
        EventBus.getDefault().register(this);  //事件的注册
        //获取之前的数据
        showDataSetUp();
        string = SPUtils.get(SetUpReserveActivity.this, "config", "").toString();
        textTx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                judgePermission();
            }
        });
        //性别
        rgSex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb_male) {//男
                    rbFemale.setChecked(false);
                    rbMale.setChecked(true);
                    sex = "1";
                } else if (checkedId == R.id.rb_female) {//女
                    rbFemale.setChecked(true);
                    rbMale.setChecked(false);
                    sex = "2";
                }

            }
        });

        //时间
        radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb_noon) {//午
                    rbNight.setChecked(false);
                    rbNoon.setChecked(true);
                    begin_night = "1";
                } else if (checkedId == R.id.rb_night) {//晚
                    rbNight.setChecked(true);
                    rbNoon.setChecked(false);
                    begin_night = "2";
                }
            }
        });
        //会议
        radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb_noon2) {//午
                    rbNight2.setChecked(false);
                    rbNoon2.setChecked(true);
                    end_night = "1";
                } else if (checkedId == R.id.rb_night2) {//晚
                    rbNight2.setChecked(true);
                    rbNoon2.setChecked(false);
                    end_night = "2";
                }
            }
        });

        editCb.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    editCb.setText("");
//                    cb_id = "";
//                    cb_did = "";
                    d_money = "";
                    if (!cb_did.equals("")) {
                        textCaidan.setText("已添加");
                        textCaidan.setTextColor(getResources().getColor(R.color.color_4d89ea));
                        textCaidan.setTextSize(15);
                        editCb.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
                    } else {
                        textCaidan.setText("+");
                        textCaidan.setTextColor(getResources().getColor(R.color.color_333333));
                        textCaidan.setTextSize(20);
                        editCb.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
                    }
//                    textCaidan.setText("+");
//                    textCaidan.setTextColor(getResources().getColor(R.color.color_333333));
//                    textCaidan.setTextSize(20);
                    aBoolean = true;
                } else {
                    String string = SPUtils.get(mContext, "money", "").toString();
                    if (!string.equals("")) {
                        if (!editCb.getText().toString().equals("")) {
                            if (Float.valueOf(string) > Float.valueOf(d_money)) {
                                editCb.setText("" + string);
                                ToastUtils.shortToast(mContext, "不能小于当前宴会厅的最低餐标价格");
                                return;
                            }
                        }else{
                            editCb.setText("" + string);
                            ToastUtils.shortToast(mContext, "不能小于当前宴会厅的最低餐标价格");
                        }
                    }
                    if (editCb.getText().toString().equals("")) {
                        if (!cb_did.equals("")) {
                            textCaidan.setText("已添加");
                            textCaidan.setTextColor(getResources().getColor(R.color.color_4d89ea));
                            textCaidan.setTextSize(15);
                            editCb.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
                        } else {
                            textCaidan.setText("+");
                            textCaidan.setTextColor(getResources().getColor(R.color.color_333333));
                            textCaidan.setTextSize(20);
                            editCb.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
                        }
                    }else{
                        if (!cb_did.equals("")) {
                            textCaidan.setText("已添加");
                            textCaidan.setTextColor(getResources().getColor(R.color.color_4d89ea));
                            textCaidan.setTextSize(15);
                            editCb.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
                        } else {
                            textCaidan.setText("+");
                            textCaidan.setTextColor(getResources().getColor(R.color.color_333333));
                            textCaidan.setTextSize(20);
                            editCb.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
                        }
                    }
//                    if (!cb_did.equals("")) {
//                        textCaidan.setText("已添加");
//                        textCaidan.setTextColor(getResources().getColor(R.color.color_4d89ea));
//                        textCaidan.setTextSize(15);
//                        editCb.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
//                        aBoolean = false;
//                    } else {
//                        textCaidan.setText("+");
//                        textCaidan.setTextColor(getResources().getColor(R.color.color_333333));
//                        textCaidan.setTextSize(20);
//                        editCb.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
//                    }
//                    if(!editCb.getText().toString().equals("")){
//                        textCaidan.setText("已添加");
//                        textCaidan.setTextColor(getResources().getColor(R.color.color_4d89ea));
//                        textCaidan.setTextSize(15);
//                        aBoolean=false;
//                    }
                }
            }
        });
        editCb.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (aBoolean) {
                    d_money = s.toString();
                    cb_id = "";
                    cb_did = "";
                }
            }
        });
        showDataSpTypeMode();
        String max1 = SPUtils.get(SetUpReserveActivity.this, "max", "").toString();
        textDesk.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (!is_meeting.equals("1")) {
                    if (!s.toString().equals("")) {
                        float i = Float.valueOf(s.toString());
                        float max = Float.valueOf(max1);
                        if (i > max) {
                            textDesk.setFocusable(true);
                            textDesk.clearFocus();
                            textDesk.setText(max1 + "");
                            hideInput();
                            ToastUtils.show(SetUpReserveActivity.this, "桌数不能大于最大桌数" + max1 + "哦");
                        }
                    }
                }
            }
        });
    }

    private void showDataSetUp() {
        OkHttpUtils.post()
                .url(Api.POST_SCHEDULED_ORDER_dEL)
                .addHeader("flag", SPUtils.get(SetUpReserveActivity.this, "token", "").toString())
                .addParams("id", "" + id)
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "修改订单获取数据onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "修改订单获取数据onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(mContext, "token", "");
                            Intent intent = new Intent(mContext, LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }
                        SetUpReserveBean setUpReserveBean = JsonUtils.parseByGson(response, SetUpReserveBean.class);
                        if (beanBean.getCode().equals("0")) {
                            SetUpReserveBean.DataBeanX.DataBean data = setUpReserveBean.getData().getData();
                            String[] split = data.getBegin_time().split("-");
                            begin_year = split[0];
                            begin_month = split[1];
                            begin_day = split[2];
                            if (data.getBegin_night() == 1) {
                                rbNoon.setChecked(true);
                                rbNight.setChecked(false);
                            } else {
                                rbNight.setChecked(true);
                                rbNoon.setChecked(false);
                            }
                            rbNoon.setEnabled(false);
                            rbNight.setEnabled(false);
                            begin_night = data.getBegin_night() + "";
                            textTime1.setText("【日期】" + data.getBegin_time());
                            bid = data.getBid() + "";
                            tid = data.getTid() + "";
                            showDataRvStandardType();
                            showOffice();
                            BanquetNamelsit.clear();
                            if (setUpReserveBean.getData().getNewArr() != null) {
                                for (int i = 0; i < setUpReserveBean.getData().getNewArr().size(); i++) {
                                    BanquetNameBean banquetNameBean = new BanquetNameBean();
                                    banquetNameBean.setBid(setUpReserveBean.getData().getNewArr().get(i).getId() + "");
                                    banquetNameBean.setName(setUpReserveBean.getData().getNewArr().get(i).getNames());
                                    banquetNameBean.setValue(setUpReserveBean.getData().getNewArr().get(i).getMobiles());
                                    BanquetNamelsit.add(banquetNameBean);
                                }
                            }
                            rvType.setLayoutManager(new LinearLayoutManager(SetUpReserveActivity.this));
                            RBaseAdapter<SetUpReserveBean.DataBeanX.NewArrBean> valueBeanRBaseAdapter = new RBaseAdapter<SetUpReserveBean.DataBeanX.NewArrBean>
                                    (SetUpReserveActivity.this,
                                            R.layout.item_reserve_rv_type, setUpReserveBean.getData().getNewArr()) {
                                @Override
                                protected void fillItem(RViewHolder holder, SetUpReserveBean.DataBeanX.NewArrBean item, int position) {
                                    TextView name = holder.itemView.findViewById(R.id.name);
                                    TextView names = holder.itemView.findViewById(R.id.names);
                                    EditText groomname = holder.itemView.findViewById(R.id.groomname);
                                    EditText groomphoto = holder.itemView.findViewById(R.id.groomphoto);
                                    name.setText("" + item.getTitle());
                                    names.setText("" + item.getMobile());
                                    if (item.getNames() != null) {
                                        groomname.setText("" + item.getNames());
                                    }
                                    if (item.getMobiles() != null) {
                                        groomphoto.setText("" + item.getMobiles());
                                    }
                                    groomname.addTextChangedListener(new TextWatcher() {
                                        @Override
                                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                        }

                                        @Override
                                        public void onTextChanged(CharSequence s, int start, int before, int count) {

                                        }

                                        @Override
                                        public void afterTextChanged(Editable s) {
                                            BanquetNamelsit.get(position).setBid(item.getId() + "");
                                            BanquetNamelsit.get(position).setName(groomname.getText().toString() + "");
                                        }
                                    });
                                    groomphoto.addTextChangedListener(new TextWatcher() {
                                        @Override
                                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                        }

                                        @Override
                                        public void onTextChanged(CharSequence s, int start, int before, int count) {

                                        }

                                        @Override
                                        public void afterTextChanged(Editable s) {

                                            BanquetNamelsit.get(position).setBid(item.getId() + "");
                                            BanquetNamelsit.get(position).setValue(groomname.getText().toString() + "");

                                        }
                                    });

                                }

                                @Override
                                protected int getViewType(SetUpReserveBean.DataBeanX.NewArrBean item, int position) {
                                    return 0;
                                }
                            };
                            rvType.setAdapter(valueBeanRBaseAdapter);

                            if (data.getEnd_time() != null) {
                                String[] split1 = data.getEnd_time().split("-");
                                end_year = split1[0];
                                end_month = split1[1];
                                end_day = split1[2];
                                if (data.getEnd_night() == 1) {
                                    rbNoon2.setChecked(true);
                                    rbNight2.setChecked(false);
                                } else {
                                    rbNight2.setChecked(true);
                                    rbNoon2.setChecked(false);
                                }
                                rbNoon2.setEnabled(false);
                                rbNight2.setEnabled(false);
                                end_night = "" + data.getEnd_night();//1中午2晚上
                                textTime2.setText("" + data.getEnd_time());
                            }

                            editTx.setText("" + data.getBook());
                            textPhoto.setText("" + data.getMobile());
                            sex = data.getSex() + "";
                            textDesk.setText("" + data.getDesk());
                            prepareDesk.setText("" + data.getPrepare_desk());

                            if(data.getD_money()!=null){
                                editCb.setText("" + data.getD_name());
                                d_money = data.getD_money() + "";
                            }
                            cb_id = data.getDid() + "";
                            cb_did = data.getCid() + "";
                            Log.e("TAG",editCb.getText().toString()+"  123");
                            if (!editCb.getText().toString().equals("")) {
                                textCaidan.setText("已添加");
                                textCaidan.setTextColor(getResources().getColor(R.color.color_4d89ea));
                                textCaidan.setTextSize(15);
                            }


                            if (data.getSex() == 1) {
                                rbMale.setChecked(true);
                                rbFemale.setChecked(false);
                            } else if (data.getSex() == 2) {
                                rbFemale.setChecked(true);
                                rbMale.setChecked(false);
                            }
                            source_id = data.getSource_id() + "";
                            director_id = data.getDirector_id() + "";
                            tvSource.setText("" + data.getSource());
                            showData();
                            if (data.getIncrease_id() != null) {
                                increase = data.getIncrease_id() + "";
                                increase_money = data.getIncrease_money() + "";
                                textService.setText("已添加");
                                textService.setTextColor(getResources().getColor(R.color.color_4d89ea));
                                textService.setTextSize(15);
                            }

                            if (data.getContent() != null) {
                                editContent.setText("" + data.getContent());
                            }
                            if (data.getContracts() != null) {
                                for (int i = 0; i < data.getContracts().size(); i++) {
                                    ContractsBean contractsBea = new ContractsBean();
                                    contractsBea.setContract_id(data.getContracts().get(i).getContract_id());
                                    contractsBea.setContracts(data.getContracts().get(i).getContracts());
                                    mlist_rvhetong.add(contractsBea);
                                }
                            }

                            if (data.getOthers() != null) {
                                for (int i = 0; i < data.getOthers().size(); i++) {
                                    OthersBean othersBean = new OthersBean();
                                    othersBean.setOther_id(data.getOthers().get(i).getOther_id());
                                    othersBean.setOthers(data.getOthers().get(i).getOthers());
                                    mlist_rvqita.add(othersBean);
                                }
                            }

                            showRVQTImg();//其他
                            showRVHtImg();//合同
                            if (setUpReserveBean.getData().getScheduled_deposit() != null) {
                                showAddData(setUpReserveBean.getData().getScheduled_deposit());
                            }
                        }
                    }
                });

    }

    private void showAddData(List<SetUpReserveBean.DataBeanX.ScheduledDepositBean> newArrs) {

        for (int i = 0; i < newArrs.size(); i++) {
            view = LinearLayout.inflate(SetUpReserveActivity.this, R.layout.add_reserve_view, null);
            view.setTag(i);//设置标记
            initFind(view, i);
            initShowData(newArrs, i);
            view.setPadding(0, 10, 0, 0);
            lineAddView.addView(view);
            if (newArrs.size() > 0) {
                if (!string.equals("1")) {
                    textAdd.setEnabled(false);
                }
                if (!JurisdictionUtils.getReceiptStatus(SetUpReserveActivity.this)) {
                    imgview.setVisibility(View.INVISIBLE);
                    number.setVisibility(View.INVISIBLE);
                    bh.setVisibility(View.INVISIBLE);
                }
            }
        }
    }

    private void initShowData(List<SetUpReserveBean.DataBeanX.ScheduledDepositBean> newArrs, int i) {
        if (newArrs.get(i).getType() == 1) {//预收
            rbDb.setChecked(false);
            rbYs.setChecked(true);
            money.setText("" + newArrs.get(i).getMoney());
            tv_type.setText("" + newArrs.get(i).getType_name());
            tv_type_id.setText("" + newArrs.get(i).getType_id());
            tv_mode.setText("" + newArrs.get(i).getPay_name());
            tv_mode_id.setText("" + newArrs.get(i).getPay_type());
            ids.setText("" + newArrs.get(i).getId());
            Glide.with(SetUpReserveActivity.this).load(newArrs.get(i).getImage()).into(imgview);
            number.setText("" + newArrs.get(i).getNum());
            lineDbr.setVisibility(View.GONE);
            line_ys.setVisibility(View.VISIBLE);
        } else if (newArrs.get(i).getType() == 2) {//担保人
            rbDb.setChecked(true);
            rbYs.setChecked(false);
            edit_dbr.setText("" + newArrs.get(i).getG_name());
            edit_dbr_id.setText(newArrs.get(i).getGid() + "");
            dbr_id.setText(newArrs.get(i).getId() + "");
            lineDbr.setVisibility(View.VISIBLE);
            line_ys.setVisibility(View.GONE);
        }
    }

    private void showOffice() {
        OkHttpUtils.post()
                .url(Api.POST_INDEX_SCHEDULED)
                .addHeader("flag", SPUtils.get(mContext, "token", "").toString())
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "宴会厅onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "宴会厅onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(mContext, "token", "");
                            Intent intent = new Intent(mContext, LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }
                        ScheduledBean scheduledBean = JsonUtils.parseByGson(response, ScheduledBean.class);
                        for (int i = 0; i < scheduledBean.getData().size(); i++) {
                            if (bid.equals(scheduledBean.getData().get(i).getId() + "")) {
                                text1.setText("" + scheduledBean.getData().get(i).getName());
                               // SPUtils.put(mContext, "money", scheduledBean.getData().get(i).getMoney() + "");
                            }
                        }
                    }
                });
    }


    //其他
    private void showRVQTImg() {
        if (mlist_qita.size() + mlist_rvqita.size() < 20) {
            mlist_qita.add(0, "");
        }
        for (int i = 0; i < mlist_rvqita.size(); i++) {
            mlist_qita.add(mlist_qita.size(), mlist_rvqita.get(i).getOthers());
        }
        rvQita.setLayoutManager(new GridLayoutManager(SetUpReserveActivity.this, 3));
        RBaseAdapter<String> rBaseAdapter = new RBaseAdapter<String>(SetUpReserveActivity.this, R.layout.item_returnvist_img, mlist_qita) {
            @Override
            protected void fillItem(RViewHolder holder, String item, int position) {
                RoundImageView img = holder.itemView.findViewById(R.id.img_round);
                ImageView img_detele = holder.itemView.findViewById(R.id.img_detele);
                if (!item.equals("")) {
                    img_detele.setVisibility(View.VISIBLE);
                    Glide.with(SetUpReserveActivity.this).load(item).into(img);
                } else {
                    img_detele.setVisibility(View.GONE);
                    Glide.with(SetUpReserveActivity.this).load(R.mipmap.icon_rv_img).into(img);
                }
                img_detele.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (item.contains("http")) {
                            for (int i = 0; i < mlist_rvqita.size(); i++) {
                                if (mlist_rvqita.get(i).getOthers().equals("" + item)) {
                                    mlist_rvqita.remove(i);
                                }
                            }
                            for (int i = 0; i < mlist_qita.size(); i++) {
                                if (mlist_qita.get(i).equals("" + item)) {
                                    mlist_qita.remove(i);
                                }
                            }
                        } else {
                            mlist_qita.remove(position);
                        }
                        if (mlist_qita.size() < 20) {
                            if (!mlist_qita.contains("")) {
                                mlist_qita.add(0, "");
                            }
                        }
                        notifyDataSetChanged();
                    }
                });
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (item.equals("")) {
                            img_type = 2;
                            showImg();

                        } else {
                            if (mlist_qita.size() != 20) {
                                ImageViewpagerDialog.show(SetUpReserveActivity.this, null, mlist_qita, position - 1);
                            } else {
                                ImageViewpagerDialog.show(SetUpReserveActivity.this, null, mlist_qita, position);
                            }
//                            ImageViewpagerDialog.show(SetUpReserveActivity.this, null, mlist_qita, position);
                        }
                    }
                });
            }

            @Override
            protected int getViewType(String item, int position) {
                return 0;
            }
        };
        rvQita.setAdapter(rBaseAdapter);
    }

    //合同
    private void showRVHtImg() {
        if (mlist_hetong.size() + mlist_rvhetong.size() < 20) {
            mlist_hetong.add(0, "");
        }
        for (int i = 0; i < mlist_rvhetong.size(); i++) {
            mlist_hetong.add(mlist_hetong.size(), mlist_rvhetong.get(i).getContracts());
        }
        rvHetong.setLayoutManager(new GridLayoutManager(SetUpReserveActivity.this, 3));
        RBaseAdapter<String> rBaseAdapter = new RBaseAdapter<String>(SetUpReserveActivity.this, R.layout.item_returnvist_img, mlist_hetong) {
            @Override
            protected void fillItem(RViewHolder holder, String item, int position) {
                RoundImageView img = holder.itemView.findViewById(R.id.img_round);
                ImageView img_detele = holder.itemView.findViewById(R.id.img_detele);
                if (!item.equals("")) {
                    img_detele.setVisibility(View.VISIBLE);
                    Glide.with(SetUpReserveActivity.this).load(item).into(img);
                } else {
                    img_detele.setVisibility(View.GONE);
                    Glide.with(SetUpReserveActivity.this).load(R.mipmap.icon_rv_img).into(img);
                }
                img_detele.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (item.contains("http")) {
                            for (int i = 0; i < mlist_rvhetong.size(); i++) {
                                if (mlist_rvhetong.get(i).getContracts().equals("" + item)) {
                                    mlist_rvhetong.remove(i);
                                }
                            }
                            for (int i = 0; i < mlist_hetong.size(); i++) {
                                if (mlist_hetong.get(i).equals("" + item)) {
                                    mlist_hetong.remove(i);
                                }
                            }
                        } else {
                            mlist_hetong.remove(position);
                        }
                        if (mlist_hetong.size() < 20) {
                            if (!mlist_hetong.contains("")) {
                                mlist_hetong.add(0, "");
                            }
                        }
                        notifyDataSetChanged();
                    }
                });
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (item.equals("")) {
                            img_type = 1;
                            showImg();
                        } else {
                            if (mlist_hetong.size() != 20) {
                                ImageViewpagerDialog.show(SetUpReserveActivity.this, null, mlist_hetong, position - 1);
                            } else {
                                ImageViewpagerDialog.show(SetUpReserveActivity.this, null, mlist_hetong, position);
                            }

                        }
                    }
                });
            }

            @Override
            protected int getViewType(String item, int position) {
                return 0;
            }
        };
        rvHetong.setAdapter(rBaseAdapter);
    }


    private void showImg() {
        if (img_type == 2) {//其他
            if (mlist_qita.get(0).equals("")) {
                mlist_qita.remove(0);
            }
            int i = 20 - mlist_qita.size();
            PictureSelector.create(this)
                    .openGallery(PictureMimeType.ofImage())
                    .loadImageEngine(GlideEngine.createGlideEngine())
                    .selectionMode(100)
                    .maxSelectNum(i)
                    .previewImage(true)
                    .compress(true)//图片是否压缩
                    .minimumCompressSize(70)// 小于100kb的图片不压缩
                    .forResult(PictureConfig.CHOOSE_REQUEST);
        } else {
            if (mlist_hetong.get(0).equals("")) {
                mlist_hetong.remove(0);
            }
            int i = 20 - mlist_hetong.size();
            PictureSelector.create(this)
                    .openGallery(PictureMimeType.ofImage())
                    .loadImageEngine(GlideEngine.createGlideEngine())
                    .selectionMode(100)
                    .maxSelectNum(i)
                    .previewImage(true)
                    .compress(true)//图片是否压缩
                    .minimumCompressSize(70)// 小于100kb的图片不压缩
                    .forResult(PictureConfig.CHOOSE_REQUEST);
        }

    }

    //预收款的类型与方式
    private void showDataSpTypeMode() {
        OkHttpUtils.post()
                .url(Api.POST_PAYMENT)
                .addHeader("flag", SPUtils.get(SetUpReserveActivity.this, "token", "").toString())
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "预收款的类型与方式onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "预收款的类型与方式onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(SetUpReserveActivity.this, "token", "");
                            Intent intent = new Intent(SetUpReserveActivity.this, LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }
                        SpReserveBean spReserveBean = JsonUtils.parseByGson(response, SpReserveBean.class);
                        if (spReserveBean.getCode().equals("0")) {
                            for (int i = 0; i < spReserveBean.getData().getType().size(); i++) {
                                TypePay typePay = new TypePay();
                                typePay.setId(spReserveBean.getData().getType().get(i).getId() + "");
                                typePay.setName(spReserveBean.getData().getType().get(i).getName());
                                SpTypeList.add(typePay);
                            }
                            for (int i = 0; i < spReserveBean.getData().getPay().size(); i++) {
                                TypePay typePay = new TypePay();
                                typePay.setId(spReserveBean.getData().getPay().get(i).getId() + "");
                                typePay.setName(spReserveBean.getData().getPay().get(i).getName());
                                SpModeList.add(typePay);
                            }
                        }
                    }
                });
    }

    //获取宴会厅的类型
    private void showDataRvStandardType() {
        RvReserveList.clear();
        OkHttpUtils.post()
                .url(Api.POST_STANDARD_TYPE)
                .addHeader("flag", SPUtils.get(SetUpReserveActivity.this, "token", "").toString())
                .addParams("bid", "" + bid)
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "获取宴会厅的类型onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "获取宴会厅的类型onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(SetUpReserveActivity.this, "token", "");
                            Intent intent = new Intent(SetUpReserveActivity.this, LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }
                        RvStandardTypeBean rvStandardTypeBean = JsonUtils.parseByGson(response, RvStandardTypeBean.class);
                        if (rvStandardTypeBean.getCode().equals("0")) {
                            types = rvStandardTypeBean.getData().getType();
                            for (int i = 0; i < types.size(); i++) {
                                Log.e("tag", tid + "  " + types.get(i).getId());
                                if (tid.equals("" + types.get(i).getId())) {
                                    types.get(i).setaBoolean(true);
                                } else {
                                    types.get(i).setaBoolean(false);
                                }
                            }

                            rvStandardType.setLayoutManager(new GridLayoutManager(SetUpReserveActivity.this, 3));
                            RBaseAdapter<RvStandardTypeBean.DataBean.TypeBean> rvReserveBeanRBaseAdapter = new RBaseAdapter<RvStandardTypeBean.DataBean.TypeBean>(SetUpReserveActivity.this, R.layout.item_reserve_activity_rv,
                                    types) {
                                @Override
                                protected void fillItem(RViewHolder holder, RvStandardTypeBean.DataBean.TypeBean item, int position) {
                                    CheckBox checkbox = holder.itemView.findViewById(R.id.checkbox);
                                    checkbox.setChecked(item.isaBoolean());
                                    checkbox.setEnabled(false);
                                    if (item.isaBoolean()) {
                                        SPUtils.put(SetUpReserveActivity.this, "money", item.getMoney() + "");
                                        tid=item.getId()+"";
                                        if (item.getIs_meet() == 1) {
                                            is_meeting = "1";
                                            lineIsMeet.setVisibility(View.VISIBLE);
                                            rbNoon.setText("上午");
                                            rbNoon2.setText("上午");
                                            rbNight.setText("下午");
                                            rbNight2.setText("下午");
                                            text2.setText("【 人 数 】");
                                            text3.setVisibility(View.GONE);
                                            prepareDesk.setVisibility(View.GONE);
                                        } else {
                                            rbNoon.setText("中午");
                                            rbNight.setText("晚上");
                                            is_meeting = "2";
                                            lineIsMeet.setVisibility(View.GONE);
                                            text2.setText("【 桌 数 】");
                                            text3.setVisibility(View.VISIBLE);
                                            prepareDesk.setVisibility(View.VISIBLE);
                                        }
                                    }
                                    checkbox.setText(item.getName());

                                }

                                @Override
                                protected int getViewType(RvStandardTypeBean.DataBean.TypeBean item, int position) {
                                    return 0;
                                }
                            };
                            rvStandardType.setAdapter(rvReserveBeanRBaseAdapter);
                        }
                    }
                });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.back, R.id.text_Add, R.id.text1, R.id.img_Cb, R.id.tv_view, R.id.tv_source
            , R.id.text_service, R.id.text_reserve, R.id.text_message, R.id.text_caidan,R.id.line6})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back://返回
                finish();
                break;
            case R.id.text_Add://添加预收款
                //ToastUtils.shortToast(SetUpReserveActivity.this,"1开启  2否  "+string);

                int childCount = lineAddView.getChildCount();
                if (childCount != 0) {
                    boolean addviewinfo = addviewinfo();
                    if (addviewinfo) {
                        return;
                    }
                }
                showView();
                break;
            case R.id.line6:
                editContent.setFocusable(true);
                editContent.setFocusableInTouchMode(true);
                editContent.requestFocus();
                initInput();
                break;
            case R.id.img_Cb://选择餐标
                editCb.setFocusable(true);
                editCb.clearFocus();
                DataReserveCbDialog.show(SetUpReserveActivity.this, null, tid).setListener(new DataReserveCbDialog.OnDialogClickListener() {
                    @Override
                    public void onPositiveClick(String id, String did, String name, String d_moneys) {
                        if (!name.equals("")) {
                            editCb.setText("" + name);
                            cb_id = id;
                            cb_did = did;
                            cid = did;
                            d_money = d_moneys;
                            textCaidan.setText("已添加");
                            textCaidan.setTextColor(getResources().getColor(R.color.color_4d89ea));
                            textCaidan.setTextSize(15);
                        }
                    }
                });
                break;
            case R.id.text_caidan://餐标菜单
                if (editCb.getText().toString().equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "请先输入餐标");
                    return;
                }
                MealLabelActivity.start(cb_did, cb_id, tid);
                break;
            case R.id.tv_view://客户经理
                DataSelectionDialog.show(SetUpReserveActivity.this, null, Api.POST_ZERO_VIEW).setListener(new DataSelectionDialog.OnDialogClickListener() {
                    @Override
                    public void onPositiveClick(String id, String name) {
                        director_id = id + "";
                        tvView.setText("" + name);
                    }
                });
                break;
            case R.id.tv_source://客户来源
                DataSelectionDialog.show(SetUpReserveActivity.this, null, Api.POST_SCHEDULED_SOURCE).setListener(new DataSelectionDialog.OnDialogClickListener() {
                    @Override
                    public void onPositiveClick(String id, String name) {
                        source_id = id + "";
                        tvSource.setText("" + name);
                    }
                });
                break;
            case R.id.text_service:
                IncrementServiceActivity.start(increase);
                break;
            case R.id.text_reserve://预定

                if (tid.equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "请先选择类型");
                    return;
                }
                if (editTx.getText().toString().equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "预订人不能为空");
                    return;
                }
                if (textPhoto.getText().toString().equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "预订人手机号不能为空");
                    return;
                }
                if (textPhoto.getText().toString().length() != 11) {
                    ToastUtils.show(SetUpReserveActivity.this, "请输入正确的手机号码");
                    return;
                }
                if (source_id.equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "请先选择客户来源");
                    return;
                }
                if (director_id.equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "请先选择客户经理");
                    return;
                }
                if(!DatePhotoUtils.isPhone(textPhoto.getText().toString())){
                    ToastUtils.show(SetUpReserveActivity.this, "请输入正确的手机号码");
                    return;
                }
//                if(editCb.getText().toString().equals("")){
//                    ToastUtils.show(SetUpReserveActivity.this, "餐标不能为空不能为空");
//                    return;
//                }
                if (aBoolean) {
                    String string = SPUtils.get(mContext, "money", "").toString();
                    if (!string.equals("")) {
                        if (!editCb.getText().toString().equals("")) {
                            if(!d_money.equals("null")){
                                if (Float.valueOf(string) > Float.valueOf(d_money)) {
                                    editCb.setText("" + string);
                                    ToastUtils.shortToast(mContext,"不能低于最低餐标"+string+"元");
//                                ToastUtils.shortToast(mContext, "不能小于当前宴会厅的最低餐标价格");
                                    return;
                                }
                            }
                            }
                    }
                }


                String data = null;
                String strings;
                String endString;
                String[] split = textTime1.getText().toString().replace("【日期】", "").split("-");
                String[] split2 = textTime2.getText().toString().split("-");
                if (is_meeting.equals("1")) {
                    if (begin_night.equals("1")) {
                        strings = "上午";
                    } else {
                        strings = "下午";
                    }
                    if (end_night.equals("1")) {
                        endString = "上午";
                    } else {
                        endString = "下午";
                    }
                    data = "确定要预订" + split[0] + "年" + split[1] + "月" + split[2] + "日" + strings + "至" + split2[0] + "年" + split2[1] + "月" + split2[2] + "日" + endString + "  " +
                            text1.getText().toString() + "吗？";
                } else {
                    if (begin_night.equals("1")) {
                        strings = "中午";
                    } else {
                        strings = "晚上";
                    }
                    data = "确定要预订" + split[0] + "年" + split[1] + "月" + split[2] + "日" + strings + "  " +
                            text1.getText().toString() + "吗？";
                }

                SendReserveDialog.show(SetUpReserveActivity.this, null, data).setListener(new SendReserveDialog.OnDialogClickListener() {
                    @Override
                    public void onPositiveClick(String s) {
                        if (s.equals("1")) {
                            type = 1;
                            SPUtils.put(SetUpReserveActivity.this, "currentDate", split[0] + "-" + split[1] + "-" + split[2]);
                            SPUtils.put(SetUpReserveActivity.this, "homeorder", split[0] + "-" + split[1] + "-" + split[2] + "-" + begin_night + "-" + bid);
                            showFileImg(1);
                        }
                    }
                });
                break;
            case R.id.text_message://发短信
                if (tid.equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "请先选择类型");
                    return;
                }
                if (editTx.getText().toString().equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "预订人不能为空");
                    return;
                }
                if (textPhoto.getText().toString().equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "预订人手机号不能为空");
                    return;
                }
                if (textPhoto.getText().toString().length() != 11) {
                    ToastUtils.show(SetUpReserveActivity.this, "请输入正确的手机号码");
                    return;
                }
                if (source_id.equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "请先选择客户来源");
                    return;
                }
                if (director_id.equals("")) {
                    ToastUtils.show(SetUpReserveActivity.this, "请先选择客户经理");
                    return;
                }
                if(!DatePhotoUtils.isPhone(textPhoto.getText().toString())){
                    ToastUtils.show(SetUpReserveActivity.this, "请输入正确的手机号码");
                    return;
                }
//                if(editCb.getText().toString().equals("")){
//                    ToastUtils.show(SetUpReserveActivity.this, "餐标不能为空不能为空");
//                    return;
//                }
                if (aBoolean) {
                    String strin = SPUtils.get(mContext, "money", "").toString();
                    if (!strin.equals("")) {
                        if (!editCb.getText().toString().equals("")) {
                            if (!d_money.equals("null")) {
                                if (Float.valueOf(strin) > Float.valueOf(d_money)) {
                                    editCb.setText("" + strin);
                                    ToastUtils.shortToast(mContext, "不能低于最低餐标" + string + "元");
//                                ToastUtils.shortToast(mContext, "不能小于当前宴会厅的最低餐标价格");
                                    return;
                                }
                            }
                        }
                    }
                }

                String datames = null;
                String stringsmes;
                String endStringmes;
                String[] splitmes = textTime1.getText().toString().replace("【日期】", "").split("-");
                String[] split2mes = textTime2.getText().toString().split("-");
                if (is_meeting.equals("1")) {
                    if (begin_night.equals("1")) {
                        stringsmes = "上午";
                    } else {
                        stringsmes = "下午";
                    }
                    if (end_night.equals("1")) {
                        endStringmes = "上午";
                    } else {
                        endStringmes = "下午";
                    }
                    datames = "确定要预订" + splitmes[0] + "年" + splitmes[1] + "月" + splitmes[2] + "日" + stringsmes + "至" + split2mes[0] + "年" + split2mes[1] + "月" + split2mes[2] + "日" + endStringmes + "  " +
                            text1.getText().toString() + "，并发送预订信息给客户吗？";
                } else {
                    if (begin_night.equals("1")) {
                        stringsmes = "中午";
                    } else {
                        stringsmes = "晚上";
                    }
                    datames = "确定要预订" + splitmes[0] + "年" + splitmes[1] + "月" + splitmes[2] + "日" + stringsmes + "  " +
                            text1.getText().toString() + "，并发送预订信息给客户吗？";
                }
                SendReserveDialog.show(SetUpReserveActivity.this, null, datames).setListener(new SendReserveDialog.OnDialogClickListener() {
                    @Override
                    public void onPositiveClick(String s) {
                        if (s.equals("1")) {
                            type = 2;
                            SPUtils.put(SetUpReserveActivity.this, "currentDate", splitmes[0] + "-" + splitmes[1] + "-" + splitmes[2]);
                            SPUtils.put(SetUpReserveActivity.this, "homeorder", splitmes[0] + "-" + splitmes[1] + "-" + splitmes[2] + "-" + begin_night + "-" + bid);
                            showFileImg(2);
                        }
                    }
                });
                break;

        }
    }
    private void initInput() {
        InputMethodManager inputManager = (InputMethodManager)editContent.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(editContent, 0);
    }
    private void showDataAddReserve(int type) {
        mlsit.clear();
        for (int i = 0; i < lineAddView.getChildCount(); i++) {
            int childCount = lineAddView.getChildCount();
            if (childCount != 0) {
//                boolean addviewinfo = addviewinfo();
//                if (addviewinfo) {
//                    return;
//                } else {
                    AddViewInfoBean addViewInfoBean = new AddViewInfoBean();
                    View childAt = lineAddView.getChildAt(i);
                    initFind(childAt, i);
                    if (rbYs.isChecked()) {
                        if(!money.getText().toString().equals("")){
                            BigDecimal a = new BigDecimal(money.getText().toString());
                            BigDecimal b = new BigDecimal("0");
                            int val2 = a.compareTo(b);
                            if(val2==1){
                                AddViewInfoBean.AddViewInfo addViewInfoList = addViewInfoBean.getAddViewInfoList();
                                addViewInfoList.setMoney(money.getText().toString());
                                if(!tv_type_id.getText().toString().equals("")){
                                    addViewInfoList.setType_id(tv_type_id.getText().toString());
                                }else{
                                    ToastUtils.shortToast(SetUpReserveActivity.this,"请填写预付款支付类型");
                                    mlsit.clear();
                                    return;
                                }
                                if(!tv_mode_id.getText().toString().equals("")){
                                    addViewInfoList.setPay_type(tv_mode_id.getText().toString());
                                }else{
                                    ToastUtils.shortToast(SetUpReserveActivity.this,"请填写预付款支付方式");
                                    mlsit.clear();
                                    return;
                                }
                                if(!text_img.getText().toString().equals("")){
                                    addViewInfoList.setImage(text_img.getText().toString());
                                }
                                if(!number.getText().toString().equals("")){
                                    addViewInfoList.setNum(number.getText().toString());
                                }
                                addViewInfoList.setType("1");
                                if (!ids.getText().toString().equals("")) {
                                    addViewInfoList.setId(ids.getText().toString());
                                }
                                mlsit.add(addViewInfoList);
                            }
                        }
                    } else if (rbDb.isChecked()) {
                        if(!edit_dbr_id.getText().toString().equals("")){
                            AddViewInfoBean.Guarantee guarantee = addViewInfoBean.getGuaranteeList();
                            guarantee.setType("2");
                            if (!dbr_id.getText().toString().equals("")) {
                                guarantee.setId(dbr_id.getText().toString());
                            }
                            guarantee.setGuarantee(edit_dbr_id.getText().toString());
                            mlsit.add(guarantee);
                        }

                    }
                }
//            }

        }
        if (mlsit.size() == 0) {
            confirm = "";
        } else {
            Gson gson = new Gson();
            confirm = gson.toJson(mlsit);
        }
        String strngimg = "";
        Gson gsons = new Gson();
        banquet_name = gsons.toJson(BanquetNamelsit);

        StringBuffer stringBuffer = new StringBuffer();

        if (mlist_rvqita.size() != 0) {
            for (int i = 0; i < mlist_rvqita.size(); i++) {
                if (i == mlist_rvqita.size() - 1) {
                    stringBuffer.append(mlist_rvqita.get(i).getOther_id() + "");
                } else {
                    stringBuffer.append(mlist_rvqita.get(i).getOther_id() + ",");
                }

            }
            strngimg = other + stringBuffer.toString();
        }
        if (!strngimg.equals("")) {
            other = strngimg;

        }
        if (!other.equals("")) {
            if (other.substring(other.length() - 1).equals(",")) {
                other = other.substring(0, other.length() - 1);
            }
        }

        StringBuffer stringBuffer1 = new StringBuffer();
        String string1 = "";

        if (mlist_rvhetong.size() != 0) {
            for (int i = 0; i < mlist_rvhetong.size(); i++) {
                if (i == mlist_rvhetong.size() - 1) {
                    stringBuffer1.append(mlist_rvhetong.get(i).getContract_id() + "");
                } else {
                    stringBuffer1.append(mlist_rvhetong.get(i).getContract_id() + ",");
                }

            }
            string1 = contract + stringBuffer1.toString();
        }
        if (!string1.equals("")) {
            contract = string1;

        }
        if (!contract.equals("")) {
            if (contract.substring(contract.length() - 1).equals(",")) {
                contract = contract.substring(0, contract.length() - 1);
            }
        }
        Log.e("TAG","flag    "+SPUtils.get(mContext, "token", "").toString());
        Log.e("TAG","id    "+id);
        Log.e("TAG","book    "+editTx.getText().toString());
        Log.e("TAG","sex    "+sex);
        Log.e("TAG","desk    "+textDesk.getText().toString());
        Log.e("TAG","prepare_desk    "+prepareDesk.getText().toString());
        Log.e("TAG","did    "+cb_id);
        String s = editCb.getText().toString();
        if(s.equals("null")){
            s="";
        }
        Log.e("TAG","d_money    "+s);
        Log.e("TAG","d_name    "+s);
        Log.e("TAG","cid    "+cb_did);
        Log.e("TAG","source    "+source_id);
        Log.e("TAG","content    "+editContent.getText().toString());
        Log.e("TAG","contract    "+contract);

        Log.e("TAG","other    "+other);
        Log.e("TAG","increase_id    "+increase);
        Log.e("TAG","banquet_name    "+banquet_name);

        Log.e("TAG","confirm    "+confirm);
        Log.e("TAG","director_id    "+director_id);
        Log.e("TAG","type    "+type);

        OkHttpUtils.post()
                .url(Api.POST_SCHEDULED_ORDER_SAVE)
                .addHeader("flag", SPUtils.get(mContext, "token", "").toString())
                .addParams("id", id)
                .addParams("book", editTx.getText().toString())
                .addParams("mobile", textPhoto.getText().toString())
                .addParams("sex", sex)
                .addParams("desk", textDesk.getText().toString())
                .addParams("prepare_desk", prepareDesk.getText().toString())
                .addParams("did", "" + cb_id)//
                .addParams("d_money", s)
                .addParams("d_name",s)//餐标名称
                .addParams("cid", cb_did)
                .addParams("source", source_id)
                .addParams("content", editContent.getText().toString())
                .addParams("contract", contract)
                .addParams("other", other)
                .addParams("increase_id", increase)
                .addParams("banquet_name", banquet_name)
                .addParams("confirm", confirm)
                .addParams("director_id", director_id)
                .addParams("type", type + "")
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "预定下单onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "预定下单onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("0")) {
                            ToastUtils.show(SetUpReserveActivity.this, beanBean.getMsg());
                            SPUtils.put(SetUpReserveActivity.this, "aBoolean", "1");
                            EventBean eventBusBean = new EventBean();
                            eventBusBean.setAnInt(0);
                            EventBus.getDefault().post(eventBusBean); //普通事件发布
                            Intent intent = new Intent(mContext, MainActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(intent);
                            finish();
                            finish();
                        } else if (beanBean.getCode().equals("4")) {
                            SPUtils.put(mContext, "token", "");
                            Intent intent = new Intent(mContext, LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        } else {
                            ToastUtils.show(SetUpReserveActivity.this, beanBean.getMsg());
                        }

                    }
                });
    }

    private void showView() {
        view = LinearLayout.inflate(SetUpReserveActivity.this, R.layout.add_reserve_view, null);
        view.setTag(lineAddView.getChildCount());//设置标记
        initFind(view, lineAddView.getChildCount());
        view.setPadding(0, 10, 0, 0);
        lineAddView.addView(view);
        if (!string.equals("1")) {
            textAdd.setEnabled(false);
        }
        if (!JurisdictionUtils.getReceiptStatus(SetUpReserveActivity.this)) {
            imgview.setVisibility(View.INVISIBLE);
            number.setVisibility(View.INVISIBLE);
            bh.setVisibility(View.INVISIBLE);
        }
    }


    private void initFind(View view, int childCount) {
        text_title = view.findViewById(R.id.text_title);
        number = view.findViewById(R.id.number);
        imgview = view.findViewById(R.id.imgview);
        money = view.findViewById(R.id.money);
        text_img = view.findViewById(R.id.text_img);
        tv_type = view.findViewById(R.id.tv_type);
        tv_type_id = view.findViewById(R.id.tv_type_id);
        tv_mode = view.findViewById(R.id.tv_mode);
        tv_mode_id = view.findViewById(R.id.tv_mode_id);
        rbYs = view.findViewById(R.id.rb_ys);
        rbDb = view.findViewById(R.id.rb_db);
        lineDbr = view.findViewById(R.id.line_dbr);
        edit_dbr = view.findViewById(R.id.edit_dbr);
        img_dbr = view.findViewById(R.id.img_dbr);
        edit_dbr_id = view.findViewById(R.id.edit_dbr_id);
        line_ys = view.findViewById(R.id.line_ys);
        dbr_id = view.findViewById(R.id.dbr_id);
        ids = view.findViewById(R.id.id);
        view1 = view.findViewById(R.id.view1);
        bh = view.findViewById(R.id.bh);
        rbDb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int img = (int) view.getTag();
                for (int i = 0; i < lineAddView.getChildCount(); i++) {
                    View childAt = lineAddView.getChildAt(i);
                    initFind(childAt, i);
                    if (i == img) {
                        rbDb.setChecked(true);
                        rbYs.setChecked(false);
                        lineDbr.setVisibility(View.VISIBLE);
                        line_ys.setVisibility(View.GONE);
                    }
                }
            }
        });
        rbYs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int img = (int) view.getTag();
                for (int i = 0; i < lineAddView.getChildCount(); i++) {
                    View childAt = lineAddView.getChildAt(i);
                    initFind(childAt, i);
                    if (i == img) {
                        rbDb.setChecked(false);
                        rbYs.setChecked(true);
                        lineDbr.setVisibility(View.GONE);
                        line_ys.setVisibility(View.VISIBLE);
                    }
                }
            }
        });


        img_dbr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int img = (int) view.getTag();
                DataGuaranteeDialog.show(SetUpReserveActivity.this, null, Api.POST_GUARANTEE).setListener(new DataGuaranteeDialog.OnDialogClickListener() {
                    @Override
                    public void onPositiveClick(String id, String name) {
                        for (int i = 0; i < lineAddView.getChildCount(); i++) {
                            View childAt = lineAddView.getChildAt(i);
                            initFind(childAt, i);
                            if (i == img) {
                                edit_dbr.setText("" + name);
                                edit_dbr_id.setText("" + id);
                            }
                        }
                    }
                });
            }
        });
        edit_dbr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int img = (int) view.getTag();
                DataGuaranteeDialog.show(SetUpReserveActivity.this, null, Api.POST_GUARANTEE).setListener(new DataGuaranteeDialog.OnDialogClickListener() {
                    @Override
                    public void onPositiveClick(String id, String name) {
                        for (int i = 0; i < lineAddView.getChildCount(); i++) {
                            View childAt = lineAddView.getChildAt(i);
                            initFind(childAt, i);
                            if (i == img) {
                                edit_dbr.setText("" + name);
                                edit_dbr_id.setText("" + id);
                            }
                        }

                    }
                });
            }
        });
        tv_type.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int img = (int) view.getTag();
                DataReserveAddViewDialog.show(SetUpReserveActivity.this, null, SpTypeList).setListener(new DataReserveAddViewDialog.OnDialogClickListener() {
                    @Override
                    public void onPositiveClick(String id, String name) {
                        for (int i = 0; i < lineAddView.getChildCount(); i++) {
                            View childAt = lineAddView.getChildAt(i);
                            initFind(childAt, i);
                            if (i == img) {
                                tv_type.setText("" + name);
                                tv_type_id.setText("" + id);
                            }
                        }
                    }
                });
            }
        });

        tv_mode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int img = (int) view.getTag();
                DataReserveAddViewDialog.show(SetUpReserveActivity.this, null, SpModeList).setListener(new DataReserveAddViewDialog.OnDialogClickListener() {
                    @Override
                    public void onPositiveClick(String id, String name) {
                        for (int i = 0; i < lineAddView.getChildCount(); i++) {
                            View childAt = lineAddView.getChildAt(i);
                            initFind(childAt, i);
                            if (i == img) {
                                tv_mode.setText("" + name);
                                tv_mode_id.setText("" + id);
                            }
                        }
                    }
                });
            }
        });
        childCount = childCount + 1;
        String d = DatePhotoUtils.numberToChinese(childCount);
        if (d.equals("一")) {
            text_title.setText("   首次金额");
        } else {
            text_title.setText("   " + d + "次金额");
        }

        imgview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!text_img.getText().toString().equals("")) {
                    ImageDialog.show(SetUpReserveActivity.this, null, text_img.getText().toString());
                    return;
                }
                img = (int) view.getTag();
                PictureSelector.create(SetUpReserveActivity.this)
                        .openGallery(PictureMimeType.ofImage())
                        .loadImageEngine(GlideEngine.createGlideEngine())
                        .selectionMode(100)
                        .maxSelectNum(1)
                        .previewImage(true)
                        .compress(true)//图片是否压缩
                        .minimumCompressSize(70)// 小于100kb的图片不压缩
                        .forResult(123);
            }
        });
    }

    // 普通事件的处理
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void handleEvent(EventBusResereBean carrier) {
        if (carrier != null) {
            if (carrier.getType() == 1) {
                if (type_time == 1) {
                    String[] two = carrier.getStarttime().split("-");
                    begin_year = two[0];
                    begin_month = two[1];
                    begin_day = two[2];
                    textTime1.setText("【日期】" + carrier.getStarttime().replace("-", "-"));
                } else {
                    String[] two = carrier.getStarttime().split("-");
                    end_year = two[0];
                    end_month = two[1];
                    end_day = two[2];
                    textTime2.setText(carrier.getStarttime().replace("-", "-"));
                }
            } else if (carrier.getType() == 4) {
                if(!carrier.getMoney().equals("")){
                    increase_money = carrier.getMoney();
                    increase = carrier.getId();
                    textService.setText("已添加");
                    textService.setTextColor(getResources().getColor(R.color.color_4d89ea));
                    textService.setTextSize(15);
                }else{
                    increase_money = "";
                    increase = carrier.getId();
                    textService.setText("+");
                    textService.setTextColor(getResources().getColor(R.color.color_333333));
                    textService.setTextSize(20);
                }

//                increase_money = carrier.getMoney();
//                increase = carrier.getId();
//                textService.setText("已添加");
//                textService.setTextColor(getResources().getColor(R.color.color_4d89ea));
//                textService.setTextSize(15);
            } else if (carrier.getType() == 5) {
                if (!carrier.getId().equals("")) {
//                    cb_id = carrier.getId();
                    if (!cb_id.equals("")) {
                        cb_id = carrier.getId();
                    }
                }
                cb_did = carrier.getDid();
                textCaidan.setText("已添加");
                textCaidan.setTextColor(getResources().getColor(R.color.color_4d89ea));
                textCaidan.setTextSize(15);
            }

        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this); //解除注册
    }

    //客户经理 客户来源
    private void showData() {
        OkHttpUtils.post()
                .url(Api.POST_ZERO_VIEW)
                .addHeader("flag", SPUtils.get(mContext, "token", "").toString())
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "客户经理onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "客户经理onResponse   " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(mContext, "token", "");
                            Intent intent = new Intent(mContext, LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }
                        ZeroSpSourceBean zeroSpSourceBean = JsonUtils.parseByGson(response, ZeroSpSourceBean.class);
                        if (zeroSpSourceBean.getCode().equals("0")) {
                            list = zeroSpSourceBean.getData().getList();
                            if (list.size() != 0) {
                                for (int i = 0; i < list.size(); i++) {
                                    if (director_id.equals(list.get(i).getId() + "")) {

                                        director_id = list.get(i).getId() + "";
                                        tvView.setText("" + list.get(i).getUsername());
                                    }
                                }
                            }
                        }
                    }
                });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 0:
                if (data == null) {
                    return;
                }
                Uri uri = data.getData();
                String[] contacts = DatePhotoUtils.getPhoneContacts(SetUpReserveActivity.this, uri);
                editTx.setText("" + contacts[0]); //
                textPhoto.setText("" + contacts[1]);
                break;
            case 188:
                if (data == null) {
                    return;
                }

                List<LocalMedia> localMedia = PictureSelector.obtainMultipleResult(data);
                if (localMedia != null) {
                    if (img_type == 2) {
                        for (int i = mlist_qita.size() - 1; i >= 0; i--) {
                            if (mlist_qita.get(i).contains("http")) {
                                mlist_qita.remove(i);
                            }
                        }
//                        mlist_qita.clear();
                        for (int i = 0; i < localMedia.size(); i++) {
                            mlist_qita.add(localMedia.get(i).getCompressPath());
                        }
                        showRVQTImg();
                    } else {
                        for (int i = mlist_hetong.size() - 1; i >= 0; i--) {
                            if (mlist_hetong.get(i).contains("http")) {
                                mlist_hetong.remove(i);
                            }
                        }
//                        mlist_hetong.clear();
                        for (int i = 0; i < localMedia.size(); i++) {
                            mlist_hetong.add(localMedia.get(i).getCompressPath());
                        }
                        showRVHtImg();
                    }
                }
                break;
            case 123:
                if (data == null) {
                    return;
                }
                final String[] imgString = new String[1];
                List<LocalMedia> localMedias = PictureSelector.obtainMultipleResult(data);
                String realPath = localMedias.get(0).getRealPath();
                PostFormBuilder builder = OkHttpUtils.post()
                        .url(Api.POSY_UPLOADS);
                File file = new File(realPath);
                builder.addFile("file[]", file.getName(), file);
                showLoadingDialog();
                builder.build().execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        hideLoadingDialog();
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        hideLoadingDialog();
                        Log.e("TAG", "其他图片onResponse~~~~~~~~    " + response);
                        ImgBean imgBean = JsonUtils.parseByGson(response, ImgBean.class);
                        if (imgBean.getCode().equals("0")) {
                            imgString[0] = imgBean.getData().get(0).getUrl();
                            AddViewImg addViewImg = new AddViewImg();
                            addViewImg.setImg_type(img);
                            addViewImg.setImgurl(imgString[0]);
                            addViewImg.setId(imgBean.getData().get(0).getId());
                            addViewImgList.add(addViewImg);
                        }
                        for (int i = 0; i < lineAddView.getChildCount(); i++) {
                            View childAt = lineAddView.getChildAt(i);
                            initFind(childAt, i);
                            for (int j = 0; j < addViewImgList.size(); j++) {
                                if (i == addViewImgList.get(j).getImg_type()) {
//                                    text_img.setText("" + addViewImgList.get(j).getImgurl());
                                    text_img.setText("" + addViewImgList.get(j).getId());
                                    Glide.with(SetUpReserveActivity.this).load(addViewImgList.get(j).getImgurl()).into(imgview);
                                }
                            }

                        }
                    }
                });

                break;

        }
    }

    public void showFileImg(int type) {
        if (mlist_qita.size() != 0) {
            if (mlist_qita.get(0).equals("")) {
                mlist_qita.remove(0);
            }
        }

        if (mlist_qita.size() != 0) {
            initUploadQT();
        } else {
            if (mlist_hetong.size() != 0) {
                if (mlist_hetong.get(0).equals("")) {
                    mlist_hetong.remove(0);
                }
            }
            if (mlist_hetong.size() != 0) {
                mlist_qita.add("");
                initUploadHT();
            } else {
                mlist_qita.add("");
                mlist_hetong.add("");
                showDataAddReserve(type);
                return;
            }
        }
    }

    //其他
    private void initUploadQT() {
        PostFormBuilder builder = OkHttpUtils.post()
                .url(Api.POSY_UPLOADS);
        for (int i = 0; i < mlist_qita.size(); i++) {
            if (!mlist_qita.get(i).contains("http")) {
                String path = mlist_qita.get(i);
                if (path != null && !path.isEmpty()) {
                    File file = new File(path);
                    builder.addFile("file[]", file.getName(), file);
                }
            }
        }
        showLoadingDialog();
        builder.build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                Log.e("TAG", "其他图片onError~~~~~~~~    " + e.getMessage());
                hideLoadingDialog();
            }

            @Override
            public void onResponse(String response, int id) {
                hideLoadingDialog();
                Log.e("TAG", "其他图片onResponse~~~~~~~~    " + response);
                ImgBean imgBean = JsonUtils.parseByGson(response, ImgBean.class);
                StringBuffer sb = new StringBuffer();
                if (imgBean.getCode().equals("0")) {
                    for (int i = 0; i < imgBean.getData().size(); i++) {
                        ImgBean.DataBean dataBean = imgBean.getData().get(i);
                        sb.append(dataBean.getId() + ",");
                    }
                    other = sb.toString();
                }
                initUploadHT();
            }
        });
    }

    //合同
    private void initUploadHT() {
        PostFormBuilder builder = OkHttpUtils.post()
                .addHeader("Content-Type", "application/json; charset=utf-8")
                .addHeader("flag", SPUtils.get(mContext, "token", "").toString())
                .url(Api.POSY_UPLOADS);
        for (int i = 0; i < mlist_hetong.size(); i++) {
            if (!mlist_hetong.get(i).contains("http")) {
                String path = mlist_hetong.get(i);
                if (path != null && !path.isEmpty()) {
                    File file = new File(path);
                    builder.addFile("file[]", file.getName(), file);
                }
            }
        }
        showLoadingDialog();
        builder.build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                hideLoadingDialog();
                Log.e("TAG", "合同图片onError~~~~~~~~    " + e.getMessage());
            }

            @Override
            public void onResponse(String response, int id) {
                hideLoadingDialog();
                Log.e("TAG", "合同图片onResponse~~~~~~~~    " + response);
                ImgBean imgBean = JsonUtils.parseByGson(response, ImgBean.class);
                StringBuffer sb = new StringBuffer();
                if (imgBean.getCode().equals("0")) {
                    for (int i = 0; i < imgBean.getData().size(); i++) {
                        ImgBean.DataBean dataBean = imgBean.getData().get(i);
                        sb.append(dataBean.getId() + ",");
                    }
                    contract = sb.toString();
                }
                showDataAddReserve(type);
            }
        });
    }

    //预收款 图片
    public class AddViewImg {
        private String imgurl;
        private int img_type;
        private String id;

        public String getImgurl() {
            return imgurl;
        }

        public void setImgurl(String imgurl) {
            this.imgurl = imgurl;
        }

        public int getImg_type() {
            return img_type;
        }

        public void setImg_type(int img_type) {
            this.img_type = img_type;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }
    }


    //新娘新郎
    public class BanquetNameBean {
        private String id;
        private String name;
        private String value;

        public String getBid() {
            return id;
        }

        public void setBid(String bid) {
            this.id = bid;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    protected void hideInput() {
        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        View v = getWindow().peekDecorView();
        if (null != v) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    }


    public class OthersBean {
        /**
         * other_id : 91
         * others : http://lxy.yskxfs.com/uploads/uploads/apifile/20210423/09efaaf046905a94cb29fb342827eca7.png
         */

        private String other_id;
        private String others;

        public String getOther_id() {
            return other_id;
        }

        public void setOther_id(String other_id) {
            this.other_id = other_id;
        }

        public String getOthers() {
            return others;
        }

        public void setOthers(String others) {
            this.others = others;
        }
    }

    public class ContractsBean {
        /**
         * contract_id : 92
         * contracts : http://lxy.yskxfs.com/uploads/uploads/apifile/20210423/75d4d96f391a9497b768cbdd2683f42f.jpg
         */

        private String contract_id;
        private String contracts;

        public String getContract_id() {
            return contract_id;
        }

        public void setContract_id(String contract_id) {
            this.contract_id = contract_id;
        }

        public String getContracts() {
            return contracts;
        }

        public void setContracts(String contracts) {
            this.contracts = contracts;
        }
    }

    //确认方式添加判断
    private boolean addviewinfo() {
        for (int i = 0; i < lineAddView.getChildCount(); i++) {
            View childAt = lineAddView.getChildAt(i);
            initFind(childAt, i);
            if (rbYs.isChecked()) {
                if (money.getText().toString().equals("")) {
                    ToastUtils.shortToast(SetUpReserveActivity.this, "请先完善确认方式");
                    return true;
                }
                if (JurisdictionUtils.getReceiptStatus(SetUpReserveActivity.this)) {
                    if (number.getText().toString().equals("")) {
                        ToastUtils.shortToast(SetUpReserveActivity.this, "请填写收据编号");
                        return true;
                    }
                }

            } else if (rbDb.isChecked()) {
                if (edit_dbr.getText().toString().equals("")) {
                    ToastUtils.shortToast(SetUpReserveActivity.this, "请先完善确认方式");
                    return true;
                }
            }
        }
        return false;
    }


    protected void judgePermission() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            // 检查该权限是否已经获取
            // 权限是否已经 授权 GRANTED---授权  DINIED---拒绝
            //手机状态权限
            String[] SdCdPermission = {Manifest.permission.READ_CONTACTS};
            if (ContextCompat.checkSelfPermission(this, SdCdPermission[0]) != PackageManager.PERMISSION_GRANTED) {
                // 如果没有授予该权限，就去提示用户请求
                ActivityCompat.requestPermissions(this, SdCdPermission, 350);
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NotNull @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        boolean hasAllGranted = true;
        //判断是否拒绝  拒绝后要怎么处理 以及取消再次提示的处理
        for (int grantResult : grantResults) {
            if (grantResult == PackageManager.PERMISSION_DENIED) {
                hasAllGranted = false;
                break;
            }
        }
        if (hasAllGranted) { //同意权限做的处理,开启服务提交通讯录
            Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
            startActivityForResult(intent, 0);

        } else {    //拒绝授权做的处理，弹出弹框提示用户授权
            dealwithPermiss(SetUpReserveActivity.this, permissions[0]);
        }
    }

    public void dealwithPermiss(final Activity context, String permission) {
        if (!ActivityCompat.shouldShowRequestPermissionRationale(context, permission)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(SetUpReserveActivity.this);
            builder.setTitle("操作提示")
                    .setMessage("注意：当前缺少必要权限！\n请点击“设置”-“权限”-打开所需权限\n最后点击两次后退按钮，即可返回")
                    .setPositiveButton("去授权", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", context.getApplicationContext().getPackageName(), null);
                            intent.setData(uri);
                            context.startActivity(intent);
                        }
                    })
                    .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(SetUpReserveActivity.this, "取消授权", Toast.LENGTH_SHORT).show();
                        }
                    }).show();

        }
    }
}